<template>
  <div id="AsnDetail">
    <div class="detail">
      <v-navMenu :detailNav="detailNav"
                 :menuData="menuData"
                 @setMentActive="setMentActive"></v-navMenu>
      <component :inputData="detailData"
                 :is="currentComponent"></component>
    </div>
  </div>
</template>

<script>
import navMenu from "commons/NavMenu";
import baseMixin from "@/mixins/BaseMixin";

export default {
  name: "AsnDetail",
  mixins: [baseMixin],
  data () {
    return {
      flag: true,
      newFlag: false,
      selectData: {},
      detailData: {},
      menuData: [
        { label: this.$t('config.general'), index: "1" },
        { label: this.$t('config.address'), index: "2" },
        { label: this.$t('config.billAdress'), index: "3" },
        { label: this.$t('config.other'), index: "4" },
        { label: this.$t('config.bill'), index: "5" },
        { label: this.$t('config.task'), index: "6" },
        { label: this.$t('config.handler'), index: "7" }
      ],
      detailNav: "1",
      componentConfig: [
        {
          name: "Common",
          label: this.$t('config.general'),
          component: () => import('./page/Common.vue')
        },
        {
          name: "Address",
          label: this.$t('config.address'),
          component: () => import('./page/Address.vue')
        },
        {
          name: this.$t('config.billAdress'),
          label: "Billaddress",
          component: () => import('./page/Billaddress.vue')
        },
        {
          name: this.$t('config.other'),
          label: "Other",
          component: () => import('./page/Other.vue')
        },
        {
          name: this.$t('config.bill'),
          label: "Bill",
          component: () => import('./page/Bill.vue')
        },
        {
          name: this.$t('config.task'),
          label: "Task",
          component: () => import('./page/Task.vue')
        },
        {
          name: this.$t('config.handler'),
          label: "Hand",
          component: () => import('./page/Hand.vue')
        }
      ]
    }
  },
  computed: {
    currentComponent () {
      return this.componentConfig[this.detailNav - 1].component;
    }
  },
  methods: {
    setMentActive (key) {
      this.detailNav = key;
    },
    async getData () {
      try {
        let key = encodeURI(encodeURI(this.selectData.storerkey))
        let res = await this.$api.get(`/queryStorer12/${key}/${this.selectData.type}`);
        
          this.detailData = res.bean;
        
      } catch (e) {
        this.$message.error(e);
      }
    },
  },
  mounted () {
    this.newFlag = this.$store.state.newFlag;
    if (Object.keys(this.$store.state.skip).length !== 0) {
      let data = this.$store.state.skip;
      this.detailData = data.detail;
      this.selectData = data.routeData;
      this.detailNav = data.detailNav;
      this.newFlag = data.newFlag;
      this.$store.commit("setNewFlag", data.newFlag);
    } else if (this.newFlag) {
      this.detailData = {
        type: "1",
        sourceversion: 0,
        cartongroup: "STD",
        pickcode: "NSPFIFO",
        createpataskonrfreceipt: "0",
        calculateputawaylocation: "2",
        defaultstrategy: "STD",
        defaultskurotation: "LOT",
        defaultrotation: "1",
        rollreceipt: "1",
        receiptvalidationtemplate: " ",
        allowautocloseforpo: "1",
        allowautocloseforasn: "1",
        allowautocloseforps: "1",
        allowsystemgeneratedlpn: "1",
        allowduplicatelicenseplates: "1",
        allowcommingledlpn: "1",
        allowsinglescanreceiving: "1",
        lpnlength: 6,
        applicationid: "00",
        sscc1stdigit: 0,
        uccvendornumber: " ",
        caselabeltype: "STD",
        autoprintlabellpn: "1",
        autoprintlabelputaway: "1",
        lpnstartnumber: " ",
        nextlpnnumber: " ",
        lpnrollbacknumber: " ",
        autocloseasn: "0",
        autoclosepo: "0",
        defaultreturnsloc: "RETURN",
        defaultqcloc: "QC",
        piskuxloc: "0",
        ccskuxloc: "0",
        ccdiscrepancyrule: "STD",
        ccadjbyrf: "0",
        orderbreakdefault: "0",
        skusetuprequired: "0",
        defaultqclocout: "PICKTO",
        kship_Carrier: 0,
        reqreasonshortship: 0,
        containerexchangeflag: 0,
        cartonizeftdflt: "0",
        defftlabelprint: "0",
        deffttaskcontrol: "0",
        tempforasn: "N",
        mixedlpnputstrategy: "STD",
        rtxneedweight: 0
      }
    } else {
      this.selectData = this.$store.state.routeData;
      this.getData();
    }
  },
  watch: {},
  components: {
    "v-navMenu": navMenu
  },
}
</script>

<style scoped>
</style>
